package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.elder.business.domain.RetreatRecordsVO;
import com.elder.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.business.domain.RetreatRecords;
import com.elder.business.service.IRetreatRecordsService;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 老人退住Controller
 * 
 * @author elder
 * @date 2023-11-26
 */
@RestController
@RequestMapping("/business/retreatRecords")
public class RetreatRecordsController extends BaseController
{
    @Autowired
    private IRetreatRecordsService retreatRecordsService;

    /**
     * 查询老人退住列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(String elderName,String startTime,String endTime,String applyStatus,Integer pageNum,Integer pageSize) {
        return retreatRecordsService.getRetreatRecordsList(elderName,startTime,endTime,applyStatus,pageNum,pageSize);
    }

    /**
     * 导出老人退住列表
     */
    @Anonymous
    @Log(title = "老人退住", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RetreatRecords retreatRecords)
    {
        List<RetreatRecords> list = retreatRecordsService.selectRetreatRecordsList(retreatRecords);
        ExcelUtil<RetreatRecords> util = new ExcelUtil<RetreatRecords>(RetreatRecords.class);
        util.exportExcel(response, list, "老人退住数据");
    }

    /**
     * 获取老人退住详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(retreatRecordsService.selectRetreatRecordsById(id));
    }

    /**
     * 新增老人退住
     */
    @Anonymous
    @Log(title = "老人退住", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RetreatRecordsVO retreatRecords)
    {
        return toAjax(retreatRecordsService.insertRetreatRecords(retreatRecords));
    }

    /**
     * 修改老人退住
     */
    @Anonymous
    @Log(title = "老人退住", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RetreatRecordsVO retreatRecords)
    {
        return toAjax(retreatRecordsService.updateRetreatRecords(retreatRecords));
    }

    /**
     * 删除老人退住
     */
    @Anonymous
    @Log(title = "老人退住", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(retreatRecordsService.delRetreatRecordsByIds(ids));
    }

    @Anonymous
    @RequestMapping("/approve")
    public AjaxResult approve(Long id,Long elderId, String applyStatus) {
        return toAjax(retreatRecordsService.updateEgressRegisterApprove(id,elderId, applyStatus));
    }
}
